<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <cpn></cpn>
    <cpn ref="aaa"></cpn>
    <button @click="btnClick">点击按钮调用子组件方法</button>
</div>

<template id="cpn">
    <div>我是子组件</div>
</template>
<script src="../../js/vue.js"></script>

<script>
    const vue = new Vue({
        el: "#app",
        data: {
            message: "Hello vue,你好！"
        },
        methods: {
            btnClick(){
                console.log(this.$children);
                // this.$children[0].showMessage();
                /*for(let c of this.$children){
                    c.showMessage();
                    console.log(c.name);
                }*/
                this.$refs.aaa.showMessage();
                console.log(this.$refs.aaa.name);
            }
        },
        components:{
            cpn:{
                template: '#cpn',
                data(){
                    return {
                        name: 'zhangsan'
                    }
                },
                methods:{
                    showMessage(){
                        console.log("子组件的方法==showMessage")
                    }
                }
            }
        }
    });
</script>
</body>
</html>